// 控件管理接口
import { ajaxService } from '@/utils/request';
import {
  ApprovalRelease,
  ApprovalReleaseParams,
  EditApprovalRelease,
  DelApprovalRelease
} from './type';
import { repoSingleApprovalParam } from './repType';
import { AddNode } from './addNodeType';

const env = import.meta.env;
const baseURL = env.VITE_APP_BASE_URL;
/**
 *
 * @param data 发起审批(新增)
 * @returns
 */
export async function AddApprovalRelease(data: ApprovalRelease) {
  return ajaxService({
    url: '/flow/open/remote_api/initiate/approval/flow',
    method: 'post',
    baseURL,
    data
  });
}
/**
 * 获取审批流程分页列表(发起的审批列表)
 * @param params
 * @returns
 */
export async function getApprovalReleaseList(params: ApprovalReleaseParams) {
  return ajaxService<{ content: any; pageable: any }>({
    url: '/flow/open/remote_api/approval/page',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 通过审批编号获取已发布的审批信息
 * @param approvalCode 审批编号
 * @returns
 */
export async function getApprovalReleaseByApprovalCode(approvalCode: string) {
  return ajaxService<{ repoSingleApprovalParam?: repoSingleApprovalParam }>({
    url: `/flow/open/remote_api/approval/info/${approvalCode}`,
    method: 'get',
    baseURL
  });
}
/**
 * 参与人审批
 * @param data
 * @returns
 */
export async function editApprovalRelease(data: EditApprovalRelease) {
  return ajaxService({
    url: '/flow/open/remote_api/approval',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 撤回审批流程
 * @param data
 * @returns
 */
export async function delApprovalRelease(data: DelApprovalRelease) {
  return ajaxService({
    url: `/flow/open/remote_api/approval`,
    method: 'delete',
    baseURL,
    data
  });
}
/**
 * 加签
 * @param data
 * @returns
 */
export async function addApprovalNode(data: AddNode) {
  return ajaxService({
    url: '/flow/open/remote_api/add/sign',
    method: 'post',
    baseURL,
    data
  });
}
